<template>
  <a-card class="ax_sticky_top">
    <a-flex :align="'center'" :justify="'space-between'">
      <div class="flex gap-1">
        <Tool />
        <slot></slot>
      </div>
      <div>
        <a-button v-if="save" accesskey="s" type="primary" @click="saveData">保存</a-button>
      </div>
    </a-flex>
  </a-card>
</template>

<script setup lang="ts">
import { closeWindow } from '@/global/window/window';
import type { NotepadViewMode } from '../data/types';
import Tool from './Tool.vue';

const injectData: any = inject('data')!;
type InjectData = {
  // 内容;
  data: string;
  /* 模式 */
  mode?: NotepadViewMode;
  save?: () => any;
  id: string;
};
const props = defineProps<{
  save?: (data: any) => any;
}>();

const saveData = () => {
  let notepadData: InjectData = injectData();

  props.save && props.save(notepadData);
  closeWindow(notepadData.id);
};
</script>

<style lang="scss" scoped>
:deep(.ant-card-body) {
  padding: 0;
}
</style>
